<?php


abstract class BaseAntecedentes extends BaseObject  implements Persistent {


	
	protected static $peer;


	
	protected $id;


	
	protected $numhistoria;


	
	protected $tabaquismo;


	
	protected $alcholismo;


	
	protected $drogas;


	
	protected $alergias;


	
	protected $diabetes;


	
	protected $hipertencion;


	
	protected $encoronarias;


	
	protected $acv;


	
	protected $altipi;


	
	protected $cancer;


	
	protected $asma;


	
	protected $transpsiqui;


	
	protected $quien;

	
	protected $aHistoria;

	
	protected $aTip_antecede;

	
	protected $alreadyInSave = false;

	
	protected $alreadyInValidation = false;

	
	public function getId()
	{

		return $this->id;
	}

	
	public function getNumhistoria()
	{

		return $this->numhistoria;
	}

	
	public function getTabaquismo()
	{

		return $this->tabaquismo;
	}

	
	public function getAlcholismo()
	{

		return $this->alcholismo;
	}

	
	public function getDrogas()
	{

		return $this->drogas;
	}

	
	public function getAlergias()
	{

		return $this->alergias;
	}

	
	public function getDiabetes()
	{

		return $this->diabetes;
	}

	
	public function getHipertencion()
	{

		return $this->hipertencion;
	}

	
	public function getEncoronarias()
	{

		return $this->encoronarias;
	}

	
	public function getAcv()
	{

		return $this->acv;
	}

	
	public function getAltipi()
	{

		return $this->altipi;
	}

	
	public function getCancer()
	{

		return $this->cancer;
	}

	
	public function getAsma()
	{

		return $this->asma;
	}

	
	public function getTranspsiqui()
	{

		return $this->transpsiqui;
	}

	
	public function getQuien()
	{

		return $this->quien;
	}

	
	public function setId($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->id !== $v) {
			$this->id = $v;
			$this->modifiedColumns[] = AntecedentesPeer::ID;
		}

	} 
	
	public function setNumhistoria($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->numhistoria !== $v) {
			$this->numhistoria = $v;
			$this->modifiedColumns[] = AntecedentesPeer::NUMHISTORIA;
		}

		if ($this->aHistoria !== null && $this->aHistoria->getNumhistoria() !== $v) {
			$this->aHistoria = null;
		}

	} 
	
	public function setTabaquismo($v)
	{

		if ($this->tabaquismo !== $v) {
			$this->tabaquismo = $v;
			$this->modifiedColumns[] = AntecedentesPeer::TABAQUISMO;
		}

	} 
	
	public function setAlcholismo($v)
	{

		if ($this->alcholismo !== $v) {
			$this->alcholismo = $v;
			$this->modifiedColumns[] = AntecedentesPeer::ALCHOLISMO;
		}

	} 
	
	public function setDrogas($v)
	{

		if ($this->drogas !== $v) {
			$this->drogas = $v;
			$this->modifiedColumns[] = AntecedentesPeer::DROGAS;
		}

	} 
	
	public function setAlergias($v)
	{

		if ($this->alergias !== $v) {
			$this->alergias = $v;
			$this->modifiedColumns[] = AntecedentesPeer::ALERGIAS;
		}

	} 
	
	public function setDiabetes($v)
	{

		if ($this->diabetes !== $v) {
			$this->diabetes = $v;
			$this->modifiedColumns[] = AntecedentesPeer::DIABETES;
		}

	} 
	
	public function setHipertencion($v)
	{

		if ($this->hipertencion !== $v) {
			$this->hipertencion = $v;
			$this->modifiedColumns[] = AntecedentesPeer::HIPERTENCION;
		}

	} 
	
	public function setEncoronarias($v)
	{

		if ($this->encoronarias !== $v) {
			$this->encoronarias = $v;
			$this->modifiedColumns[] = AntecedentesPeer::ENCORONARIAS;
		}

	} 
	
	public function setAcv($v)
	{

		if ($this->acv !== $v) {
			$this->acv = $v;
			$this->modifiedColumns[] = AntecedentesPeer::ACV;
		}

	} 
	
	public function setAltipi($v)
	{

		if ($this->altipi !== $v) {
			$this->altipi = $v;
			$this->modifiedColumns[] = AntecedentesPeer::ALTIPI;
		}

	} 
	
	public function setCancer($v)
	{

		if ($this->cancer !== $v) {
			$this->cancer = $v;
			$this->modifiedColumns[] = AntecedentesPeer::CANCER;
		}

	} 
	
	public function setAsma($v)
	{

		if ($this->asma !== $v) {
			$this->asma = $v;
			$this->modifiedColumns[] = AntecedentesPeer::ASMA;
		}

	} 
	
	public function setTranspsiqui($v)
	{

		if ($this->transpsiqui !== $v) {
			$this->transpsiqui = $v;
			$this->modifiedColumns[] = AntecedentesPeer::TRANSPSIQUI;
		}

	} 
	
	public function setQuien($v)
	{

						if ($v !== null && !is_int($v) && is_numeric($v)) {
			$v = (int) $v;
		}

		if ($this->quien !== $v) {
			$this->quien = $v;
			$this->modifiedColumns[] = AntecedentesPeer::QUIEN;
		}

		if ($this->aTip_antecede !== null && $this->aTip_antecede->getId() !== $v) {
			$this->aTip_antecede = null;
		}

	} 
	
	public function hydrate(ResultSet $rs, $startcol = 1)
	{
		try {

			$this->id = $rs->getInt($startcol + 0);

			$this->numhistoria = $rs->getInt($startcol + 1);

			$this->tabaquismo = $rs->getBoolean($startcol + 2);

			$this->alcholismo = $rs->getBoolean($startcol + 3);

			$this->drogas = $rs->getBoolean($startcol + 4);

			$this->alergias = $rs->getBoolean($startcol + 5);

			$this->diabetes = $rs->getBoolean($startcol + 6);

			$this->hipertencion = $rs->getBoolean($startcol + 7);

			$this->encoronarias = $rs->getBoolean($startcol + 8);

			$this->acv = $rs->getBoolean($startcol + 9);

			$this->altipi = $rs->getBoolean($startcol + 10);

			$this->cancer = $rs->getBoolean($startcol + 11);

			$this->asma = $rs->getBoolean($startcol + 12);

			$this->transpsiqui = $rs->getBoolean($startcol + 13);

			$this->quien = $rs->getInt($startcol + 14);

			$this->resetModified();

			$this->setNew(false);

						return $startcol + 15; 
		} catch (Exception $e) {
			throw new PropelException("Error populating Antecedentes object", $e);
		}
	}

	
	public function delete($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("This object has already been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(AntecedentesPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			AntecedentesPeer::doDelete($this, $con);
			$this->setDeleted(true);
			$con->commit();
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	public function save($con = null)
	{
		if ($this->isDeleted()) {
			throw new PropelException("You cannot save an object that has been deleted.");
		}

		if ($con === null) {
			$con = Propel::getConnection(AntecedentesPeer::DATABASE_NAME);
		}

		try {
			$con->begin();
			$affectedRows = $this->doSave($con);
			$con->commit();
			return $affectedRows;
		} catch (PropelException $e) {
			$con->rollback();
			throw $e;
		}
	}

	
	protected function doSave($con)
	{
		$affectedRows = 0; 		if (!$this->alreadyInSave) {
			$this->alreadyInSave = true;


												
			if ($this->aHistoria !== null) {
				if ($this->aHistoria->isModified()) {
					$affectedRows += $this->aHistoria->save($con);
				}
				$this->setHistoria($this->aHistoria);
			}

			if ($this->aTip_antecede !== null) {
				if ($this->aTip_antecede->isModified()) {
					$affectedRows += $this->aTip_antecede->save($con);
				}
				$this->setTip_antecede($this->aTip_antecede);
			}


						if ($this->isModified()) {
				if ($this->isNew()) {
					$pk = AntecedentesPeer::doInsert($this, $con);
					$affectedRows += 1; 										 										 
					$this->setId($pk);  
					$this->setNew(false);
				} else {
					$affectedRows += AntecedentesPeer::doUpdate($this, $con);
				}
				$this->resetModified(); 			}

			$this->alreadyInSave = false;
		}
		return $affectedRows;
	} 
	
	protected $validationFailures = array();

	
	public function getValidationFailures()
	{
		return $this->validationFailures;
	}

	
	public function validate($columns = null)
	{
		$res = $this->doValidate($columns);
		if ($res === true) {
			$this->validationFailures = array();
			return true;
		} else {
			$this->validationFailures = $res;
			return false;
		}
	}

	
	protected function doValidate($columns = null)
	{
		if (!$this->alreadyInValidation) {
			$this->alreadyInValidation = true;
			$retval = null;

			$failureMap = array();


												
			if ($this->aHistoria !== null) {
				if (!$this->aHistoria->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aHistoria->getValidationFailures());
				}
			}

			if ($this->aTip_antecede !== null) {
				if (!$this->aTip_antecede->validate($columns)) {
					$failureMap = array_merge($failureMap, $this->aTip_antecede->getValidationFailures());
				}
			}


			if (($retval = AntecedentesPeer::doValidate($this, $columns)) !== true) {
				$failureMap = array_merge($failureMap, $retval);
			}



			$this->alreadyInValidation = false;
		}

		return (!empty($failureMap) ? $failureMap : true);
	}

	
	public function getByName($name, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = AntecedentesPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->getByPosition($pos);
	}

	
	public function getByPosition($pos)
	{
		switch($pos) {
			case 0:
				return $this->getId();
				break;
			case 1:
				return $this->getNumhistoria();
				break;
			case 2:
				return $this->getTabaquismo();
				break;
			case 3:
				return $this->getAlcholismo();
				break;
			case 4:
				return $this->getDrogas();
				break;
			case 5:
				return $this->getAlergias();
				break;
			case 6:
				return $this->getDiabetes();
				break;
			case 7:
				return $this->getHipertencion();
				break;
			case 8:
				return $this->getEncoronarias();
				break;
			case 9:
				return $this->getAcv();
				break;
			case 10:
				return $this->getAltipi();
				break;
			case 11:
				return $this->getCancer();
				break;
			case 12:
				return $this->getAsma();
				break;
			case 13:
				return $this->getTranspsiqui();
				break;
			case 14:
				return $this->getQuien();
				break;
			default:
				return null;
				break;
		} 	}

	
	public function toArray($keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = AntecedentesPeer::getFieldNames($keyType);
		$result = array(
			$keys[0] => $this->getId(),
			$keys[1] => $this->getNumhistoria(),
			$keys[2] => $this->getTabaquismo(),
			$keys[3] => $this->getAlcholismo(),
			$keys[4] => $this->getDrogas(),
			$keys[5] => $this->getAlergias(),
			$keys[6] => $this->getDiabetes(),
			$keys[7] => $this->getHipertencion(),
			$keys[8] => $this->getEncoronarias(),
			$keys[9] => $this->getAcv(),
			$keys[10] => $this->getAltipi(),
			$keys[11] => $this->getCancer(),
			$keys[12] => $this->getAsma(),
			$keys[13] => $this->getTranspsiqui(),
			$keys[14] => $this->getQuien(),
		);
		return $result;
	}

	
	public function setByName($name, $value, $type = BasePeer::TYPE_PHPNAME)
	{
		$pos = AntecedentesPeer::translateFieldName($name, $type, BasePeer::TYPE_NUM);
		return $this->setByPosition($pos, $value);
	}

	
	public function setByPosition($pos, $value)
	{
		switch($pos) {
			case 0:
				$this->setId($value);
				break;
			case 1:
				$this->setNumhistoria($value);
				break;
			case 2:
				$this->setTabaquismo($value);
				break;
			case 3:
				$this->setAlcholismo($value);
				break;
			case 4:
				$this->setDrogas($value);
				break;
			case 5:
				$this->setAlergias($value);
				break;
			case 6:
				$this->setDiabetes($value);
				break;
			case 7:
				$this->setHipertencion($value);
				break;
			case 8:
				$this->setEncoronarias($value);
				break;
			case 9:
				$this->setAcv($value);
				break;
			case 10:
				$this->setAltipi($value);
				break;
			case 11:
				$this->setCancer($value);
				break;
			case 12:
				$this->setAsma($value);
				break;
			case 13:
				$this->setTranspsiqui($value);
				break;
			case 14:
				$this->setQuien($value);
				break;
		} 	}

	
	public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
	{
		$keys = AntecedentesPeer::getFieldNames($keyType);

		if (array_key_exists($keys[0], $arr)) $this->setId($arr[$keys[0]]);
		if (array_key_exists($keys[1], $arr)) $this->setNumhistoria($arr[$keys[1]]);
		if (array_key_exists($keys[2], $arr)) $this->setTabaquismo($arr[$keys[2]]);
		if (array_key_exists($keys[3], $arr)) $this->setAlcholismo($arr[$keys[3]]);
		if (array_key_exists($keys[4], $arr)) $this->setDrogas($arr[$keys[4]]);
		if (array_key_exists($keys[5], $arr)) $this->setAlergias($arr[$keys[5]]);
		if (array_key_exists($keys[6], $arr)) $this->setDiabetes($arr[$keys[6]]);
		if (array_key_exists($keys[7], $arr)) $this->setHipertencion($arr[$keys[7]]);
		if (array_key_exists($keys[8], $arr)) $this->setEncoronarias($arr[$keys[8]]);
		if (array_key_exists($keys[9], $arr)) $this->setAcv($arr[$keys[9]]);
		if (array_key_exists($keys[10], $arr)) $this->setAltipi($arr[$keys[10]]);
		if (array_key_exists($keys[11], $arr)) $this->setCancer($arr[$keys[11]]);
		if (array_key_exists($keys[12], $arr)) $this->setAsma($arr[$keys[12]]);
		if (array_key_exists($keys[13], $arr)) $this->setTranspsiqui($arr[$keys[13]]);
		if (array_key_exists($keys[14], $arr)) $this->setQuien($arr[$keys[14]]);
	}

	
	public function buildCriteria()
	{
		$criteria = new Criteria(AntecedentesPeer::DATABASE_NAME);

		if ($this->isColumnModified(AntecedentesPeer::ID)) $criteria->add(AntecedentesPeer::ID, $this->id);
		if ($this->isColumnModified(AntecedentesPeer::NUMHISTORIA)) $criteria->add(AntecedentesPeer::NUMHISTORIA, $this->numhistoria);
		if ($this->isColumnModified(AntecedentesPeer::TABAQUISMO)) $criteria->add(AntecedentesPeer::TABAQUISMO, $this->tabaquismo);
		if ($this->isColumnModified(AntecedentesPeer::ALCHOLISMO)) $criteria->add(AntecedentesPeer::ALCHOLISMO, $this->alcholismo);
		if ($this->isColumnModified(AntecedentesPeer::DROGAS)) $criteria->add(AntecedentesPeer::DROGAS, $this->drogas);
		if ($this->isColumnModified(AntecedentesPeer::ALERGIAS)) $criteria->add(AntecedentesPeer::ALERGIAS, $this->alergias);
		if ($this->isColumnModified(AntecedentesPeer::DIABETES)) $criteria->add(AntecedentesPeer::DIABETES, $this->diabetes);
		if ($this->isColumnModified(AntecedentesPeer::HIPERTENCION)) $criteria->add(AntecedentesPeer::HIPERTENCION, $this->hipertencion);
		if ($this->isColumnModified(AntecedentesPeer::ENCORONARIAS)) $criteria->add(AntecedentesPeer::ENCORONARIAS, $this->encoronarias);
		if ($this->isColumnModified(AntecedentesPeer::ACV)) $criteria->add(AntecedentesPeer::ACV, $this->acv);
		if ($this->isColumnModified(AntecedentesPeer::ALTIPI)) $criteria->add(AntecedentesPeer::ALTIPI, $this->altipi);
		if ($this->isColumnModified(AntecedentesPeer::CANCER)) $criteria->add(AntecedentesPeer::CANCER, $this->cancer);
		if ($this->isColumnModified(AntecedentesPeer::ASMA)) $criteria->add(AntecedentesPeer::ASMA, $this->asma);
		if ($this->isColumnModified(AntecedentesPeer::TRANSPSIQUI)) $criteria->add(AntecedentesPeer::TRANSPSIQUI, $this->transpsiqui);
		if ($this->isColumnModified(AntecedentesPeer::QUIEN)) $criteria->add(AntecedentesPeer::QUIEN, $this->quien);

		return $criteria;
	}

	
	public function buildPkeyCriteria()
	{
		$criteria = new Criteria(AntecedentesPeer::DATABASE_NAME);

		$criteria->add(AntecedentesPeer::ID, $this->id);

		return $criteria;
	}

	
	public function getPrimaryKey()
	{
		return $this->getId();
	}

	
	public function setPrimaryKey($key)
	{
		$this->setId($key);
	}

	
	public function copyInto($copyObj, $deepCopy = false)
	{

		$copyObj->setNumhistoria($this->numhistoria);

		$copyObj->setTabaquismo($this->tabaquismo);

		$copyObj->setAlcholismo($this->alcholismo);

		$copyObj->setDrogas($this->drogas);

		$copyObj->setAlergias($this->alergias);

		$copyObj->setDiabetes($this->diabetes);

		$copyObj->setHipertencion($this->hipertencion);

		$copyObj->setEncoronarias($this->encoronarias);

		$copyObj->setAcv($this->acv);

		$copyObj->setAltipi($this->altipi);

		$copyObj->setCancer($this->cancer);

		$copyObj->setAsma($this->asma);

		$copyObj->setTranspsiqui($this->transpsiqui);

		$copyObj->setQuien($this->quien);


		$copyObj->setNew(true);

		$copyObj->setId(NULL); 
	}

	
	public function copy($deepCopy = false)
	{
				$clazz = get_class($this);
		$copyObj = new $clazz();
		$this->copyInto($copyObj, $deepCopy);
		return $copyObj;
	}

	
	public function getPeer()
	{
		if (self::$peer === null) {
			self::$peer = new AntecedentesPeer();
		}
		return self::$peer;
	}

	
	public function setHistoria($v)
	{


		if ($v === null) {
			$this->setNumhistoria(NULL);
		} else {
			$this->setNumhistoria($v->getNumhistoria());
		}


		$this->aHistoria = $v;
	}


	
	public function getHistoria($con = null)
	{
		if ($this->aHistoria === null && ($this->numhistoria !== null)) {
						$this->aHistoria = HistoriaPeer::retrieveByPK($this->numhistoria, $con);

			
		}
		return $this->aHistoria;
	}

	
	public function setTip_antecede($v)
	{


		if ($v === null) {
			$this->setQuien(NULL);
		} else {
			$this->setQuien($v->getId());
		}


		$this->aTip_antecede = $v;
	}


	
	public function getTip_antecede($con = null)
	{
		if ($this->aTip_antecede === null && ($this->quien !== null)) {
						$this->aTip_antecede = Tip_antecedePeer::retrieveByPK($this->quien, $con);

			
		}
		return $this->aTip_antecede;
	}

} 